package io.renren.modules.common.service.impl;

import io.renren.modules.common.dao.CompanyPropertyDao;
import io.renren.modules.common.viewdo.SelectOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;


import io.renren.modules.common.entity.CompanyPropertyEntity;
import io.renren.modules.common.service.CompanyPropertyService;


@Service("companyPropertyService")
public class CompanyPropertyServiceImpl extends ServiceImpl<CompanyPropertyDao, CompanyPropertyEntity> implements CompanyPropertyService {

    @Autowired
    private CompanyPropertyDao companyPropertyDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CompanyPropertyEntity> page = this.page(
                new Query<CompanyPropertyEntity>().getPage(params),
                new QueryWrapper<CompanyPropertyEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SelectOption> listOption() {
        List<SelectOption> topSelectList = new ArrayList<>();
        List<CompanyPropertyEntity> companyPropertyEntities = companyPropertyDao.selectList(null);
        topSelectList = companyPropertyEntities.stream().map(item -> new SelectOption(item.getId().toString(),item.getCompanyProppertyName())).collect(Collectors.toList());
        return topSelectList;
    }

}